<template>
  <PageWrapper title="编辑企业信息">
    <div class="py-8 bg-white flex flex-col justify-center items-center">
      <BasicForm @register="register" />
      <div class="flex justify-center">
        <a-button class="!ml-4" type="primary" @click="handleSubmit"> 提交 </a-button>
      </div>
    </div>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { onMounted, ref } from 'vue';
  import { PageWrapper } from '@/components/Page';
  import { BasicForm, useForm } from '@/components/Form';
  import { getSystemOrganization, editSystemOrganization } from '@/api/system';

  import { formSchema } from './data';

  const [register, { validate, resetFields, setFieldsValue }] = useForm({
    size: 'large',
    baseColProps: { span: 24 },
    labelWidth: 100,
    showActionButtonGroup: false,
    schemas: formSchema,
  });

  const id = ref();

  onMounted(async () => {
    resetFields();
    const organization = await getSystemOrganization();
    id.value = organization.id;
    setFieldsValue({...organization});
  });

  async function handleSubmit() {
    const values = await validate();
    await editSystemOrganization(values);
  }
</script>